package com.yoomiito.app.ui.meituan

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.base.WebViewActivity
import com.yoomiito.app.model.ShareViewData
import com.yoomiito.app.model.meituan.MeiTuanData
import com.yoomiito.app.share.ui.ShareActivity
import com.yoomiito.app.utils.ColorUtils
import com.yoomiito.app.utils.Const
import com.yoomiito.app.utils.ImageLoader
import kotlinx.android.synthetic.main.act_meituan_coupon.*
import kotlinx.android.synthetic.main.title_bar.*

class MeiTuanCouponActivity :BaseActivity<MeiTuanCouponPresenter>(){

    companion object{
        fun start(context: Context){
            val intent = Intent(context,MeiTuanCouponActivity::class.java)
            context.startActivity(intent)
        }
    }

    private var data:MeiTuanData?=null

    override fun getLayoutId(): Int = R.layout.act_meituan_coupon

    override fun newP(): MeiTuanCouponPresenter = MeiTuanCouponPresenter(App.mAppConfig)

    override fun initData(savedInstanceState: Bundle?) {
        iv_back_left.setOnClickListener { finish() }
        tv_center.text = "美团发红包啦"
        ImageLoader.getInstance().into(this,"https://mimitao-cdn.aijiamai.com/app/bg@3x.png",bg,R.drawable.default_featured_area)
        couponBuy.background = ColorUtils.background(R.color.color_FFFEE00,20f)
        shareGoods.background = ColorUtils.gradientAndRadius("#FFA66022","#FF974B11",25f,0f,25f,0f)
        buyGoods.background = ColorUtils.gradientAndRadius("#FFFCBE50","#FFFDD45D",0f,25f,0f,25f)
        couponBuy.setOnClickListener {
            WebViewActivity.start(this,data?.channelUrl,Const.Url.MeiTuan)
        }
        shareGoods.setOnClickListener {
            data?.let {
                ShareActivity.start(this, ShareViewData(arrayListOf(it.channelUrl)))
            }
        }
        buyGoods.setOnClickListener {
            WebViewActivity.start(this,data?.channelUrl,Const.Url.MeiTuan)
        }
        showLoading()
        p.meituan()
    }

    fun setData(data:MeiTuanData){
        this.data = data
        dismissLoading()
    }

}